import { queryLinkList } from "@/api/link.api";
import { Link } from "@/types/link";
import { useEffect, useState } from "react";


export const useLinkList = (): {
  linkList: Array<Link>;
  goToLink: (link: Link) => void;
} => {
  const [linkList,setLinkList ]= useState<Array<Link>>([]) 
  const getLinkList = async () => {
    const res = await queryLinkList();
    if (res.code === 200) {
      setLinkList(res.data||[])
      
    }
  };
  const goToLink = (link: Link) => {
    if (link.address) {
      window.open(link.address);
    }
  };
  useEffect(()=>{
    getLinkList()
  },[])
  return {
    linkList,
    goToLink,
  };
};
